package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.BusinesscardAdapter.MyViewHolder;

public class BusinesscardAdapter extends Adapter<MyViewHolder> {
	private Context mContext;
	private LayoutInflater mLayoutInflater;
	
	private OnMyClickListener mOnClickListener;
	
	private static final String[] titles =new String[]{
			"保存为潜在客户",
			"保存为客户及联系人"
	};
	
	private static final  int[] resIds =new int[]{
			R.drawable.ico_customer_hide,
			R.drawable.ico_customer_lx
	};
	
	public BusinesscardAdapter(Context mContext) {
		super();
		this.mContext = mContext;
		mLayoutInflater = LayoutInflater.from(mContext);
	}

	@Override
	public MyViewHolder onCreateViewHolder(ViewGroup arg0, int arg1) {
		View view = mLayoutInflater.inflate(R.layout.item_business, null, false);
		MyViewHolder holder = new MyViewHolder(view);
		return holder;
	}
	@Override
	public int getItemCount() {
		return 2;
	}


	@Override
	public void onBindViewHolder(MyViewHolder holder, int arg1) {
		String title =titles[arg1];
		holder.title.setText(title);
		holder.iv1.setImageResource(resIds[arg1]);
		final int pos =arg1;
		holder.mCardView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if (mOnClickListener!=null) {
					mOnClickListener.onClickItem(pos);
				}
			}
		});
	}

	
	public void setOnClickItemlistener(OnMyClickListener l){
		this.mOnClickListener =l;
	}
	public interface OnMyClickListener{
		
		void onClickItem(int pos);
	}
	
	public class MyViewHolder extends ViewHolder {

		ImageView iv1;
		TextView title;
		
		CardView mCardView;

		public MyViewHolder(View view) {
			super(view);
			iv1 = (ImageView) view.findViewById(R.id.iv1);
			title = (TextView) view.findViewById(R.id.tv1);
			mCardView = (CardView) view.findViewById(R.id.card_view);
		}

	}

}
